//-----------------------------------------------------------------------
// <copyright file="TestProgramFile.cs" company="Anthony Steele">
// This source forms part of the DuplicateFinder utility
// Hosted at http://www.codeplex.com/DuplicateFinder
//
// This source is available under the terms of the Microsoft Public License (Ms-PL)
// See http://duplicatefinder.codeplex.com/license
// All other rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DuplicateFinder.TestLibrary
{
    using DuplicateFinderLib;
    using NUnit.Framework;

    /// <summary>
    /// Test with the program source
    /// </summary>
    [TestFixture]
    public class TestProgramFile
    {
        /// <summary>
        /// Test with a threshhold of 4
        /// </summary>
        [Test]
        public void TestProgramThreshold4()
        {
            FileDuplicateFinderTester tester = new FileDuplicateFinderTester();
            FileDuplicateFinder process = tester.Process;
            Assert.IsNotNull(process);

            process.ReadFile(TestUtils.FullTestFilePath() + "TestProgram.txt");
            process.DuplicateThreshold = 4;
            process.FindDuplicates();

            // one block of four lines is duplicated once 
            Assert.AreEqual(0, tester.DuplicateCount);
        }

        /// <summary>
        /// Test with a threshhold of 4 andf min width 1
        /// </summary>
        [Test]
        public void TestProgramThreshold4Width1()
        {
            FileDuplicateFinderTester tester = new FileDuplicateFinderTester();
            FileDuplicateFinder process = tester.Process;
            Assert.IsNotNull(process);

            process.ReadFile(TestUtils.FullTestFilePath() + "TestProgram.txt");
            process.DuplicateThreshold = 4;
            process.FirstLineMinWidth = 1;
            process.FindDuplicates();

            // one block of four lines is duplicated once 
            Assert.AreEqual(1, tester.DuplicateCount);
            Assert.AreEqual(4, tester.LastDuplicateLength);
            Assert.AreEqual(2, tester.LastDuplicateInstanceCount);
        }

        /// <summary>
        /// Test with a threshhold of 5
        /// </summary>
        [Test]
        public void TestProgramThreshold5()
        {
            FileDuplicateFinderTester tester = new FileDuplicateFinderTester();
            FileDuplicateFinder process = tester.Process;
            Assert.IsNotNull(process);

            process.ReadFile(TestUtils.FullTestFilePath() + "TestProgram.txt");
            process.DuplicateThreshold = 5;
            process.FindDuplicates();

            // no blocks of five lines or more
            Assert.AreEqual(0, tester.DuplicateCount);
        }
    }
}
